
var oHead = document.getElementsByTagName('HEAD').item(0);
var oScript= document.createElement("script");
oScript.type = "text/javascript";
oScript.src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js";
oHead.appendChild( oScript);



/*获取url参数end*/


// var ShareLink = "{:U('Mobile/Team/info',['goods_id'=>$team[goods_id],'team_id'=>$team[team_id]])}"; //默认分享链接
// var ShareImgUrl = "http://{$Think.server.SERVER_NAME}{$team[share_img]}"; //分享图标
// var ShareTitle = "{$team[share_title]}"; //分享标题
// var ShareDesc = "{$team[share_desc]}"; //分享描述


$(function(){
	var url="http://wifi.qianlh.com";
	//var url="http://192.168.0.132:69";
//微信配置



	var u = navigator.userAgent;
	var ua = navigator.userAgent.toLowerCase();
	//android终端
	var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
	//ios终端
	var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);

	if(ua.match(/MicroMessenger/i)=="micromessenger") {

		var geturl1=url+ "/Admin/agentapi/getWeixinSign";
		$.ajax({
			type: 'get',
			dataType: "json",
			url: geturl1,
			success:function (res) {
				var sign=res.Sign;
				//console.log(sign);
				wx.config({
					debug: false,
					appId: sign.appId,
					timestamp: sign.timestamp,
					nonceStr: sign.nonceStr,
					signature: sign.signature,
					jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage','onMenuShareQQ','onMenuShareQZone','hideOptionMenu'] // 功能列表，我们要使用JS-SDK的什么功能

				});

				wx.ready(function(){

					wx.hideOptionMenu();

					// wx.onMenuShareTimeline({
					// 	title: ShareTitle, // 分享标题
					// 	link:ShareLink,
					// 	desc: ShareDesc,
					// 	imgUrl:ShareImgUrl // 分享图标
					// });




				});



			},error:function () {
				console.log("请检查您的网络");
			}
		});


	}else{

	}


});


/*图片缩放*/
	function chgdivimgwh(obj,width,height){
		 var image=new Image();
		 image.src=obj.src; //获取图像路径
		 var width1=image.width; //获取图像宽度
		 var height1=image.height; //获取图像高度
		 var a1=height1/width1;
		 var a2=height/width;
		 if(a1>a2){
		  obj.width=width;
		  obj.height=height1*width/width1;
		  obj.style.marginTop='-' + Math.round((obj.height-height)/2)+ 'px';
		 }else{
		  obj.height=height;
		  obj.width=width1*height/height1;
		  obj.style.marginLeft='-' + Math.round((obj.width-width)/2)+ 'px';
		 }
	}
	
//黑色遮罩层-隐藏
function undercover(){
	$('.mask-filter-div').hide();
}
//黑色遮罩层-显示
function cover(){
	$('.mask-filter-div').show();
}	
	

function altergoodsnum(n){
	var num = parseInt($('#number').val());
	var maxnum = parseInt($('#number').attr('max'));
	num += n;
	num <= 0 ? num = 1 :  num;
	if(num >= maxnum){
		$(this).addClass('no-mins');
		num = maxnum;
	}
	$('#store_count').text(maxnum-num); //更新库存数量
	$('#number').val(num)
}
/**
 * 提示弹窗
 * */
function showErrorMsg(msg){
    layer.open({content:msg,time:2});
}




/*倒计时*/
$.extend($.fn,{
    //懒人建站 http://www.51xuediannao.com/
    fnTimeCountDown:function(d){
        this.each(function(){
            var $this = $(this);
            var o = {
                hm: $this.find(".hm"),
                sec: $this.find(".sec"),
                mini: $this.find(".mini"),
                hour: $this.find(".hour"),
                day: $this.find(".day"),
                month:$this.find(".month"),
                year: $this.find(".year")
            };
            var f = {
                haomiao: function(n){
                    if(n < 10)return "00" + n.toString();
                    if(n < 100)return "0" + n.toString();
                    return n.toString();
                },
                zero: function(n){
                    var _n = parseInt(n, 10);//解析字符串,返回整数
                    if(_n > 0){
                        if(_n <= 9){
                            _n = "0" + _n
                        }
                        return String(_n);
                    }else{
                        return "00";
                    }
                },
                dv: function(){
                    //d = d || Date.UTC(2050, 0, 1); //如果未定义时间，则我们设定倒计时日期是2050年1月1日
                    var _d = $this.data("end") || d;
                    var now = new Date(),
                        endDate = new Date(_d);
                    //现在将来秒差值
                    //alert(future.getTimezoneOffset());
                    var dur = (endDate - now.getTime()) / 1000 , mss = endDate - now.getTime() ,pms = {
                        hm:"000",
                        sec: "00",
                        mini: "00",
                        hour: "00",
                        day: "00",
                        month: "00",
                        year: "0"
                    };
                    if(mss > 0){
                        pms.hm = f.haomiao(mss % 1000);
                        pms.sec = f.zero(dur % 60);
                        pms.mini = Math.floor((dur / 60)) > 0? f.zero(Math.floor((dur / 60)) % 60) : "00";
                        pms.hour = Math.floor((dur / 3600)) > 0? f.zero(Math.floor((dur / 3600)) % 24) : "00";
                        pms.day = Math.floor((dur / 86400)) > 0? f.zero(Math.floor((dur / 86400)) % 30) : "00";
                        //月份，以实际平均每月秒数计算
                        pms.month = Math.floor((dur / 2629744)) > 0? f.zero(Math.floor((dur / 2629744)) % 12) : "00";
                        //年份，按按回归年365天5时48分46秒算
                        pms.year = Math.floor((dur / 31556926)) > 0? Math.floor((dur / 31556926)) : "0";
                    }else{
                        pms.year=pms.month=pms.day=pms.hour=pms.mini=pms.sec="00";
                        pms.hm = "000";
                        //alert('结束了');
                        return;
                    }
                    return pms;
                },
                ui: function(){
                    if(o.hm){
                        o.hm.html(f.dv().hm);
                    }
                    if(o.sec){
                        o.sec.html(f.dv().sec);
                    }
                    if(o.mini){
                        o.mini.html(f.dv().mini);
                    }
                    if(o.hour){
                        o.hour.html(f.dv().hour);
                    }
                    if(o.day){
                        o.day.html(f.dv().day);
                    }
                    if(o.month){
                        o.month.html(f.dv().month);
                    }
                    if(o.year){
                        o.year.html(f.dv().year);
                    }
                    setTimeout(f.ui, 1);
                }
            };
            f.ui();
        });
    }
    });
/*倒计时end*/


/*返回上一页*/

function back(){
	window.history.go(-1);
	// window.location.href=document.referrer;
}

/*返回上一页end*/


/*手机号码验证*/

function checkMobile(tel) {
    var reg = /(^1[3|4|5|7|8][0-9]{9}$)/;
    if(reg.test(tel)) {
        return true;
    }else{
        return false;
    }
}

// 验证身份证
function isCardNo(card) {
    var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    if(pattern.test(card)) {
        return true;
    }else{
        return false;
    }
    // return pattern.test(card);
}

// 验证中文名称
function isChinaName(name) {
    var pattern = /^[\u4E00-\u9FA5]{1,6}$/;
    return pattern.test(name);
}


//验证qq
function isQQ(aQQ) {
	var bValidate = RegExp(/^[1-9][0-9]{4,9}$/).test(aQQ);
	if(bValidate) {
		return true;
	}else{
		return false;
	}

}



//
// $.getScript("http://res.wx.qq.com/open/js/jweixin-1.0.0.js");  //加载js文件
// $.getScript("http://res.wx.qq.com/open/js/jweixin-1.0.0.js",function(){  //加载test.js,成功后，并执行回调函数
// 	//var url="http://wifi.qianlh.com";
//
// });





/*手机号码验证end*/


//滚动加载更多
// $(window).scroll(
// 	function() {
// 		var scrollTop = $(this).scrollTop();
// 		var scrollHeight = $(document).height();
// 		var windowHeight = $(this).height();
// 		if (scrollTop + windowHeight == scrollHeight) {
// 			ajax_sourch_submit();
// 			//console.log(1);
// 			//调用加载更多
// 		}
// 	}
// );



